package com.sun.jdk.stream;

import java.util.Comparator;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * Stream接口的常用方法
 * 
 * 如果我们想要获取最大值和最小值，那么可以使用max和min方法
 */
public class StreamTest15MaxAndMin {
    public static void main(String[] args) {

        // 11. max和min
        Optional<Integer> max = Stream.of("10", "2", "3", "1", "51", "1", "3").map(var -> {
                    return Integer.parseInt(var);
                })
                .max(Comparator.comparingInt(o -> o));
        
        if(max.isPresent()){
            System.out.println(max.get());
        }

        Optional<Integer> min = Stream.of("10", "2", "3", "1", "51", "1", "3").map(Integer::parseInt)
                .min(Comparator.comparingInt(o->o));
        if(min.isPresent()){
            System.out.println(min.get());
        }

    }
}
